<script setup>
import {reactive, toRaw} from 'vue';
import server from "../../config/server.js";
import axios from "axios";
import {message} from "ant-design-vue";
import {useRouter} from "vue-router";

const router = useRouter()
const formState = reactive({
  name: '',
});
const onFinish = values => {
  console.log('Success:', values);
  axios({
    method: "post",
    contentType: "application/json",
    url: `${server.apiBaseUrl}/zdppy_amstudent_student`,
    data: toRaw(formState),
  }).then(resp => {
    formState.name = ""
    router.push("/student/list")
    message.success("添加学生成功")
  })
};
</script>
<template>
  <a-form
      :model="formState"
      autocomplete="off"
      @finish="onFinish"
  >
    <a-form-item
        label="姓名"
        name="name"
        :rules="[{ required: true, message: '学生姓名不能为空' }]"
    >
      <a-input v-model:value="formState.name"/>
    </a-form-item>
    <a-form-item>
      <a-button type="primary" html-type="submit">新增</a-button>
    </a-form-item>
  </a-form>
</template>